<?php

class FraisForfaitController extends Zend_Controller_Action {

    public function init() {
        /* Initialize action controller here */
    }

    public function indexAction() {
        // action body
    }

    public function listerAction() {
        $lesfraisForfait = new Application_Model_DbTable_FraisForfait();
        $this->view->lesfraisForfait = $lesfraisForfait->fetchAll();
    }

    public function gererAction() {
        $this->listerAction();
    }

    public function modifierAction() {
        $form = new Application_Form_FraisForfait();
        $form->envoyer->setLabel('Modifier');
        $this->view->form = $form;
        if ($this->getRequest()->isPost()) {
            $formData = $this->getRequest()->getPost();
            if ($form->isValid($formData)) {
                $id = $form->getValue('id');
                $libelle = $form->getValue('libelle');
                $montant = $form->getValue('montant');
                $lesFraisForfait = new Application_Model_DbTable_FraisForfait();
                $lesFraisForfait->modifierFraisForfait($id, $libelle, $montant);
                $this->_helper->redirector('gerer');
            } else {
                $form->populate($formData);
            }
        } else {
            $id = $this->_getParam('id', 0);
            $lesFraisForfait = new Application_Model_DbTable_FraisForfait();
            $form->populate($lesFraisForfait->obtenirFraisForfait($id));
        }
    }

}
